package dispatcher.group.gui.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import dispatcher.gui.GroupDispatcherView;

/**
 * This class waits for an ElevatorIntializeEvent to appear then starts to
 * initialize and populate new elevators based on the event
 * @author Caleb
 *
 */
public class ElevatorInitializeListener implements ActionListener {

	/**
	 * This method will create new elevators in the GUI
	 */
	@Override
	public void actionPerformed(ActionEvent arg0) {

		if (arg0 instanceof ElevatorInitializeEvent){
			ElevatorInitializeEvent event = (ElevatorInitializeEvent)arg0;
			
			// Iterates through all the elevator IDs and creates new elevators in the GUI 
			for(byte b : event.getElevatorIds()){
				GroupDispatcherView.getInstance().createElevator((int)b);
			}
			GroupDispatcherView.getInstance().refreshGUI();
		}
	}

}
